package account

import (
	"context"

	"core/contract/db"
	coreIError "core/contract/error"
	iRrpc "core/contract/grpc"
	enumGrpc "core/enum/grpc"
	"core/enum/response"
	"core/grpc/account"
	errorSvc "core/service/error"
	reqAccount "gateway/model/request/account"
)

type InfoApi struct {
	DbFactory  db.IDbFactory      `inject:""`
	RpcFactory iRrpc.IGrpcFactory `inject:""`

	reqAccount.InfoRequest
}

func (i InfoApi) Call(ctx context.Context) (interface{}, coreIError.IError) {
	// 创建一个请求消息
	req := &account.HelloRequest{Name: i.Message}
	// 调用服务端的SayHello方法
	resp, err := i.RpcFactory.Build(enumGrpc.Admin).(account.GreeterClient).SayHello(ctx, req)
	if err != nil {
		return nil, errorSvc.NewError(response.Fail, err)
	}

	return map[string]interface{}{
		"res": resp,
	}, nil
}
